<template>
  <view class="footer-bar">
	<uni-list class="list" >
	 	<uni-easyinput type="textarea" autoHeight v-model="inputText" placeholder="请输入评论" number></uni-easyinput>
	 			
	</uni-list>
	<button @click="publish" v-if="buyCourse.includes(course.id)||course.price==0">发表</button>
	<button disabled v-else>发表</button>
	
  </view>
  
  
	
</template>

<script setup>
import {filter} from '../../node_modules/sensitive-words-js/dist/index.js' 
import {addComment} from "@/apis/comment.js"
const props=defineProps({
	course:{}
	
})


let user=uni.getStorageSync('member');

let buyCourse=uni.getStorageSync('BuyCourses');
const inputText=ref("")

const emit = defineEmits();
	
const publish=async ()=>{
	if(inputText.value===""){
		uni.showToast({
			title:"请输入评论内容",
			icon:"none"
		})
		return;
	}
	console.log("发表评论");
	const { words, text } = filter.filter(inputText.value);
	
	if (words.length > 0) {
	  uni.showToast({
	  	title:"存在敏感词:"+words+",请重新输入",
	  	icon:"none"
	  })
	  setTimeout(()=>{
	    inputText.value="";
	  },1000)
	  
	  return;
	}
	
	
	const comment=ref({
		courseId:props.course.id,
		teacherId:props.course.teacherId,
		content:inputText.value,
		memberId:user.id,
		nickname:user.nickname,
		avatar:user.avatar,
		isDeleted:0,	
	})
	
	let res=await addComment(comment.value)
	
	emit("newComment")
	console.log("==============发布评论成功================");
	console.log(res);
	inputText.value="";
	
	
}	




	
</script>

<style scoped>
.footer-bar {
  display: flex;
  justify-content: space-around;
  background-color: #f8f8f8;
  padding: 10px 0;
  position: fixed;
  bottom: 0;
  width: 100%;
  box-shadow: 0 -2px 4px rgba(0, 0, 0, 0.1);
  .list{
	  width: 80%;
	  align-items: flex-start;
	  uni-easyinput {
	    min-height: 40rpx; /* 设置最小高度 */
	    max-height: 100rpx; /* 设置最大高度 */
	    resize: none; /* 禁止手动调整高度 */
	  }
    }
}

/* .footer-item {
  text-align: center;
}

.footer-item uni-icons {
  margin-bottom: 5px;
} */






</style>